//
//  FTBaseTableViewController.m
//  FashionTech
//
//  Created by JackieYip on 16/4/12.
//  Copyright © 2016年 mondial-d. All rights reserved.
//

#import "FTBaseTableViewController.h"
// Component_FTInternationalization
#import "FTInternationalization_Macro.h"
// FTMacro
#import "FTMacro_Font.h"

#import "masonry.h"
#import "SVProgressHUD.h"

@interface FTBaseTableViewController ()
@property (strong, nonatomic, readwrite) UIView *promptContainerView;
@property (strong, nonatomic, readwrite) UIImageView *promptView;
@property (strong, nonatomic, readwrite) UILabel *promptTitle;
@property (assign, nonatomic, readwrite) BOOL isShowNonNetWork;
@property (assign, nonatomic, readwrite) BOOL isShowEmpty;

@end

@implementation FTBaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupPromptContainerView];
    [self hideNetWorkPromptView];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    if ([SVProgressHUD isVisible])
        [SVProgressHUD dismiss];
}

- (BOOL)popViewControllerAfterCancelledSignIn
{
    return YES;
}
#pragma mark - promptContainerView
- (void)setupPromptContainerView
{
    self.promptContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
    [self.view insertSubview:_promptContainerView atIndex:0];
    self.promptContainerView.userInteractionEnabled = NO;
    self.promptContainerView.center = self.view.center;
    
    self.promptView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder"]];
    self.promptTitle = [[UILabel alloc] init];
    self.promptTitle.numberOfLines = 0;
    self.promptTitle.textAlignment = NSTextAlignmentCenter;
    self.promptTitle.text = FTLocalizedStringInLocalizable(@"网络访问失败，请检查您的网络设置");
    self.promptTitle.textColor = [UIColor grayColor];
    self.promptTitle.font = kFont14;
    
    [self.promptContainerView addSubview:_promptView];
    [self.promptContainerView addSubview:_promptTitle];
    
    [self.promptView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_promptContainerView.mas_top);
        make.centerX.equalTo(_promptContainerView.mas_centerX);
    }];
    
    [self.promptTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_promptView.mas_bottom).offset(10);
        make.centerX.equalTo(_promptContainerView.mas_centerX);
        make.height.equalTo(@(100));
        make.width.equalTo(_promptContainerView.mas_width);
    }];
}
#pragma mark - - netWorkPromptContainerView
- (void)hideNetWorkPromptView
{
    self.promptContainerView.hidden = YES;
    self.isShowNonNetWork = NO;
}
- (void)showNetWorkPromptView
{
    if (self.promptContainerView.center.y != self.view.center.y) {
        self.promptContainerView.center = self.view.center;
    }
    else {
        self.promptView.image = [UIImage imageNamed:@"placeholder"];
        self.promptTitle.text = FTLocalizedStringInLocalizable(@"网络访问失败，请检查您的网络设置");
        self.promptContainerView.hidden = NO;
        self.isShowNonNetWork = YES;
        self.isShowEmpty = NO;
    }
}
- (BOOL)isShowNetWorkPromptView
{
    return _isShowNonNetWork;
}
#pragma mark - - emptyPromptContainerView
- (void)hideEmptyPromptView
{
    self.promptContainerView.hidden = YES;
    self.isShowEmpty = NO;
}
- (void)showEmptyPromptViewWithImage:(UIImage *)image title:(NSString *)title
{
    if (self.promptContainerView.center.y != self.view.center.y) {
        [self showEmptyPromptViewWithImage:image title:title inCenter:self.view.center];
    }
    else {
        self.promptView.image = image;
        self.promptTitle.text = title;
        self.promptContainerView.hidden = NO;
        self.isShowEmpty = YES;
        self.isShowNonNetWork = NO;
    }
}
- (void)showEmptyPromptViewWithImage:(UIImage *)image title:(NSString *)title inCenter:(CGPoint)center
{
    self.promptContainerView.center = center;
    self.promptView.image = image;
    self.promptTitle.text = title;
    self.promptContainerView.hidden = NO;
    self.isShowEmpty = YES;
    self.isShowNonNetWork= NO;
}
- (BOOL)isShowEmptyPromptView
{
    return _isShowEmpty;
}
#pragma mark - Table view data source

/*
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 0;
}
 */

/*
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return 0;
}
 */

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
